package com.app.controller;

import com.app.mapper.jiuquan.PolicyMapper;
import com.app.model.PolicyModel;
import com.app.service.PolicyService;
import com.app.util.CommonHelp;
import com.app.util.Result;
import com.app.vo.PolicyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


//政策
@RestController
@Controller
@RequestMapping("/jiuquan/policy")
public class PolicyController {
    @Autowired
    private PolicyService policyService;

    @Autowired
    private PolicyMapper policyMapper;

    /**
     * 获取政策列表
     *
     * @param model
     * @return
     */
    @GetMapping("/getNewsList")
    public Result<Object> getNewsList(PolicyModel model) {
        PolicyVo listByModel = policyService.getListByModel(model);
        return Result.success(listByModel);
    }

    /**
     * 编辑政策
     *
     * @param model
     * @return
     */
    @PostMapping("/insertAndUpdateNews")
    public Result<Object> insertNews(@RequestBody PolicyModel model) {
        if (model.getId() != null && model.getId() > 0) {
            policyMapper.updateById(model);
        } else {
            model.setCreateTime(CommonHelp.getNowTimestamp());
            policyMapper.insert(model);
        }
        return Result.success("操作成功");
    }

    @GetMapping("/getNewsById")
    public Result<Object> getNewsById(@RequestParam("id") int id) {
        PolicyModel model = policyMapper.selectById(id);
        return Result.success(model);
    }


}
